package com.eric.media.utils;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.widget.MediaController;
import android.widget.VideoView;

/**
 * 视频播放的工具类
 * 
 * @Description TODO
 * @author lzb
 * @date 2016-1-20
 * @Copyright: Copyright (c) 2016 Shenzhen Tentinet Technology Co., Ltd. Inc.
 *             All rights reserved.
 */
public class VideoPlayUtil {

	/**
	 * 调用手机自带播放器播放本地视频
	 * @param activity 
	 * @param type 视频种类  如：type = "video/mp4";
	 * @param videoPath 视频地址 
	 */
	@SuppressLint("SdCardPath") 
	public static void playLocalVideo(Activity  activity , String type , String videoPath) {
		Intent intent = new Intent(Intent.ACTION_VIEW);
        //String type = "video/mp4";
		Uri uri = Uri.parse("file://" + videoPath);
		intent.setDataAndType(uri, type);
		activity.startActivity(intent);
	}
	
	/**
	 * 调用手机自带播放器播放本地视频
	 * @param activity 
	 * @param type 视频种类  如：type = "video/mp4";
	 * @param videoPath 视频地址 
	 */
	@SuppressLint("SdCardPath") 
	public static void playLocalVideo(Activity  activity, String videoPath) {
		Intent intent = new Intent(Intent.ACTION_VIEW);
        //String type = "video/mp4";
		Uri uri = Uri.parse("file://" + videoPath);
		intent.setData(uri);
		activity.startActivity(intent);
	}
	
	
	/**
	 * 调用手机自带播放器播放网络视频
	 * @param activity 
	 * @param type 视频种类  如：type = "video/mp4";
	 * @param videoUrl 视频播放网址
	 */
	public static void playNetVideo(Activity  activity , String type , String videoUrl) {
		Intent intent = new Intent(Intent.ACTION_VIEW);
		if (TextUtils.isEmpty(type)) {
			type = "video/*";
		}
		Uri uri = Uri.parse(videoUrl);
		intent.setDataAndType(uri, type);
		activity.startActivity(intent);
	}
	
	/**
	 * 调用手机自带播放器播放网络视频
	 * @param activity 
	 * @param videoUrl 视频播放网址 
	 */
	public static void playNetVideo(Activity  activity , String videoUrl) {
		Intent intent = new Intent(Intent.ACTION_VIEW);
		Uri uri = Uri.parse(videoUrl);
		intent.setData(uri);
		activity.startActivity(intent);
	}
	
	/**
	 * 
	 * 使用VideoView播放视频
	 * @param videoPath 视频播放网址 
	 * @param videoView VideoView对象
	 * @param isStart true 开始播放视频，否则不开始播放视频
	 */
	public static void playByVideoView(VideoView videoView,String videoPath , Context context,boolean isStart){
		Uri uri = Uri.parse(videoPath);
		videoView.setMediaController(new MediaController(context));
		videoView.setVideoURI(uri);
		if (isStart) {
			videoView.start();
		}
		videoView.requestFocus();
	}
	
	/**
	 * 开始播放VideoView
	 */
	public static void startPlayVideoView(VideoView videoView){
		videoView.start();
	}
	
}
